package com.test.blog.controller;

import com.test.blog.entity.CategoryCountEntity;
import com.test.blog.entity.TNote;
import com.test.blog.service.TNoteService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TNote)表控制层
 *
 * @author makejava
 * @since 2021-12-09 11:50:49
 */
@RestController
@RequestMapping("/note")
public class TNoteController {
    /**
     * 服务对象
     */
    @Resource
    private TNoteService tNoteService;


    /**
     * 通过主键查询单条数据
     *
     * @param noteId 主键
     * @return 单条数据
     */
    @RequestMapping("/queryById")
    public TNote queryById(@Param("noteId") Integer noteId) {
        return tNoteService.queryById(noteId);
    }

    /**
     * 查找所有数据-默认情况
     * @return tnote集合
     */
    @RequestMapping("/findAll")
    public List<TNote> findAll() {
        return tNoteService.findAll();
    }

    /**
     * 查找所有数据-点击排行
     * @return tnote集合
     */
    @RequestMapping("/findAllOrderByReadNum")
    public List<TNote> findAllOrderByReadNum() {
        return tNoteService.findAllOrderByReadNum();
    }

    /**
     * 点赞数加1
     */
    @RequestMapping("/addZanNum")
    public String addZanNum(@Param("noteId") Integer noteId) {
        tNoteService.addZanNum(noteId);
        return "success";
    }

    /**
     * 阅读数加1
     */
    @RequestMapping("/addReadNum")
    public String addReadNum(@Param("noteId") Integer noteId) {
        tNoteService.addReadNum(noteId);
        return "success";
    }

    /**
     * 统计类别的数量
     */
    @RequestMapping("/count")
    public List<CategoryCountEntity> count() {
        return tNoteService.count();
    }

    /**
     * 查找推荐的文章,按照阅读数降序排序
     * @return tnote集合
     */
    @RequestMapping("/findAllByRecommend")
    public List<TNote> findAllByRecommend() {
        return tNoteService.findAllByRecommend();
    }

    /**
     * 根据文章标题进行查找
     * @return tnote集合
     */
    @RequestMapping("/findAllByTitle")
    public List<TNote> findAllByTitle(@Param("noteTitle") String noteTitle) {
        return tNoteService.findAllByTitle(noteTitle);
    }

    /**
     * 根据类别名称进行查找
     * @return tnote集合
     */
    @RequestMapping("/findAllByCategoryName")
    public List<TNote> findAllByCategoryName(@Param("categoryName") String categoryName) {
        return tNoteService.findAllByCategoryname(categoryName);
    }
}

